package com.hujun.controller.product;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hujun.modules.product.api.ProductClassifyService;
import com.hujun.modules.product.domain.ProductClassify;

@RestController
@RequestMapping("/product-classify")
public class ProductClassifyController {

	@Autowired
	private ProductClassifyService productClassifyService;
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
	
	@RequestMapping("/v1/findProductClassifyList")
	public List<ProductClassify> findProductClassifyListV1() {
		return productClassifyService.findProductClassifyListMysqlV1();
	}
	
	@RequestMapping("/v2/findProductClassifyList")
	public List<ProductClassify> findProductClassifyListV2() {
		return productClassifyService.findProductClassifyListRedisV2();
	}

	/**
	 * 本地锁，高并发测试
	 * @return
	 */
	@RequestMapping("/v3/findProductClassifyList")
	public List<ProductClassify> findProductClassifyListBySynchronized() {
		return productClassifyService.findProductClassifyListBySynchronized();
	}

	/**
	 * 分布式，高并发测试
	 * @return
	 */
	@RequestMapping("/v4/findProductClassifyList")
	public List<ProductClassify> findProductClassifyListByRedisLock() {
		return productClassifyService.findProductClassifyListByRedisLock();
	}
	
	@RequestMapping("/testRedis")
	public String testRedis() {
		String uuid = UUID.randomUUID().toString();
		stringRedisTemplate.opsForValue().set(uuid, uuid);
		return uuid;
	}
}
